package com.ruoyi.mall.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.mall.front.vo.MallMembersVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mall.mapper.MallMembersMapper;
import com.ruoyi.mall.entity.MallMembers;
import com.ruoyi.mall.service.IMallMembersService;
import com.ruoyi.common.core.text.Convert;

/**
 * mallService业务层处理
 * 
 * @author ruoyi
 * @date 2020-05-14
 */
@Service
public class MallMembersServiceImpl implements IMallMembersService 
{
    @Autowired
    private MallMembersMapper mallMembersMapper;

    /**
     * 查询mall
     * 
     * @param membersId mallID
     * @return mall
     */
    @Override
    public MallMembers selectMallMembersById(Long membersId)
    {
        return mallMembersMapper.selectMallMembersById(membersId);
    }

    /**
     * 查询mall列表
     * 
     * @param mallMembers mall
     * @return mall
     */
    @Override
    public List<MallMembers> selectMallMembersList(MallMembers mallMembers)
    {
        return mallMembersMapper.selectMallMembersList(mallMembers);
    }

    /**
     * 新增mall
     * 
     * @param mallMembers mall
     * @return 结果
     */
    @Override
    public int insertMallMembers(MallMembers mallMembers)
    {
        mallMembers.setCreateTime(DateUtils.getNowDate());
        return mallMembersMapper.insertMallMembers(mallMembers);
    }

    /**
     * 修改mall
     * 
     * @param mallMembers mall
     * @return 结果
     */
    @Override
    public int updateMallMembers(MallMembers mallMembers)
    {
        mallMembers.setUpdateTime(DateUtils.getNowDate());
        return mallMembersMapper.updateMallMembers(mallMembers);
    }

    /**
     * 删除mall对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteMallMembersByIds(String ids)
    {
        return mallMembersMapper.deleteMallMembersByIds(Convert.toStrArray(ids));
    }

    @Override
    public AjaxResult editMember(MallMembersVo membersVo) {
        MallMembers mallMembers = this.mallMembersMapper.selectMallMembersByPhone(membersVo.getPhone());
        mallMembers.setBirthDate(membersVo.getBirthDate());
        mallMembers.setNickName(membersVo.getNickName());
        mallMembers.setSex(membersVo.getSex());
        return this.updateMallMembers(mallMembers)==1?AjaxResult.success("操作成功！"):AjaxResult.error("操作失败！");
    }

    /**
     * 删除mall信息
     * 
     * @param membersId mallID
     * @return 结果
     */
    @Override
    public int deleteMallMembersById(Long membersId)
    {
        return mallMembersMapper.deleteMallMembersById(membersId);
    }
}
